package com.cskaoyan.controller;/*
 *  @Author tsuki
 *  @Date 2021/4/12
 *  @Description
 *
 */

import com.cskaoyan.bean.user.WxUserLoginData;
import com.cskaoyan.bo.user.WxAddressBo;
import com.cskaoyan.service.user.UserService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.user.WxAddressListVo;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/wx/address")
public class WxAddressController {
    @Autowired
    UserService userService;


    @RequestMapping("list")
    public BaseRespVo list(){
        Subject subject = SecurityUtils.getSubject();
        WxUserLoginData loginData = (WxUserLoginData) subject.getPrincipal();
        //获取userId

        List<WxAddressListVo> list = userService.wxAddressQuery(loginData.getId());
        return BaseRespVo.ok(list);
    }

    @RequestMapping("detail")//?id=4
    public BaseRespVo detail(Integer id){
        Map<String,Object> map = userService.wxDetailQuery(id);
        return BaseRespVo.ok(map);
    }

    //当前userId
    @RequestMapping("save")
    public BaseRespVo save(@RequestBody WxAddressBo wxAddressBo){
        Integer integer = userService.wxAddressSave(wxAddressBo);
        return BaseRespVo.ok(integer);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map<String,Integer> map){
        userService.wxAddressDelete(map);
        return BaseRespVo.ok();
    }

}
